package com.example.shushiyunsst.fragment.main.home.child.miner.sub

import android.os.Bundle
import android.view.View
import android.widget.ImageButton
import com.example.library_common.base.BaseFragmentEx
import com.example.shushiyunsst.R
import com.google.android.material.bottomsheet.BottomSheetBehavior

class MinerPoolContentFragment : BaseFragmentEx() {

    companion object {
        fun newInstance(): MinerPoolContentFragment {
            val args = Bundle()

            val fragment = MinerPoolContentFragment()
            fragment.arguments = args
            return fragment
        }

    }

    private var onExpandListener: OnExpandListener? = null

    fun setOnExpandListener(onExpandListener: OnExpandListener?) {
        this.onExpandListener = onExpandListener
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mSuperBackPressedSupport = false
    }

    override fun getLayoutId() = R.layout.miner_pool_content_fragment

    private lateinit var panelHandler: ImageButton

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        panelHandler = view.findViewById(R.id.panelHandler)
        panelHandler.setOnClickListener {
            onExpandListener?.onExpanding()
        }

        view.findViewById<View>(R.id.liu_sui).setOnClickListener {
            start(LiuSuiFragment.newInstance())
        }
    }

    fun panelStatus(@BottomSheetBehavior.State state: Int) {
        val icon = if (state == BottomSheetBehavior.STATE_COLLAPSED) {
            R.drawable.ic_panel_arrow_up_24
        } else {
            R.drawable.ic_panel_arrow_down_24
        }
        panelHandler.setImageResource(icon)
    }

    override fun onDestroy() {
        super.onDestroy()
        onExpandListener = null
    }

    interface OnExpandListener {
        fun onExpanding()
    }
}